package com.sky.service.admin.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sky.mapper.admin.ShopMapper;
import com.sky.mapper.admin.ShoppingCartMapper;
import com.sky.pojo.Merchant;
import com.sky.pojo.ShoppingCart;
import com.sky.service.admin.ShopService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class ShopServiceImpl implements ShopService {
    private final ShopMapper shopMapper;
    //查询购物车
    private final ShoppingCartMapper shoppingCartMapper;


    /*
     * 根据查询商家信息
     * */
    @Override
    public Merchant selectMerchantInfo() {
        List<Merchant> merchants = shopMapper.selectList(Wrappers.<Merchant>lambdaQuery());
        if (CollectionUtil.isNotEmpty(merchants)){
            for (Merchant merchant : merchants) {
                log.info("查看商家信息，商家的id是：{}",merchant.getId());
                return merchant;
            }
        }
        return null;
    }

    /*
     * 查看购物车中的菜品和套餐
     * */
    @Override
    public List<ShoppingCart> selectShoppingCart() {
        List<ShoppingCart> shoppingCartLists = shoppingCartMapper.selectList(Wrappers.<ShoppingCart>lambdaQuery());
        List<ShoppingCart> shoppingCartList =new ArrayList<>();
        for (ShoppingCart shoppingCart : shoppingCartLists) {
            shoppingCartList.add(shoppingCart);
        }
        return shoppingCartList;
    }

    @Override
    public void deleteShoppingCart() {
        shoppingCartMapper.delete(Wrappers.<ShoppingCart>lambdaQuery());
    }
}
